﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ArunimaErp.Domain;
using ArunimaErp.Models;

namespace ArunimaErp.Controllers
{ 
    public class ShipmentController : Controller
    {
        private arunimaEntities db = new arunimaEntities();

        //
        // GET: /Shipment/

        public ViewResult Index(int id)
        {
            var shipmentinfo = db.shipmentinfo.Include(s => s.postyle).Where(x => x.PoStyleId == id);

            ViewBag.PoStyleId = id;

            return View(shipmentinfo.ToList());
        }

        //
        // GET: /Shipment/Create

        public ActionResult Create(int id)
        {
            ViewBag.PoStyleId = id;

            return View();
        } 

        //
        // POST: /Shipment/Create

        [HttpPost]
        public ActionResult Create(shipmentinfo shipmentinfo)
        {
            if (ModelState.IsValid)
            {
                db.shipmentinfo.Add(shipmentinfo);
                db.SaveChanges();           
            }
            return Json(JsonResponseFactory.SuccessResponse(shipmentinfo), JsonRequestBehavior.DenyGet);
        }
        
        //
        // GET: /Shipment/Edit/5
 
        public ActionResult Edit(int id)
        {
            shipmentinfo shipmentinfo = db.shipmentinfo.Find(id);
            ViewBag.PoStyleId = shipmentinfo.PoStyleId;
            return View(shipmentinfo);
        }

        //
        // POST: /Shipment/Edit/5

        [HttpPost]
        public ActionResult Edit(shipmentinfo shipmentinfo)
        {
            if (ModelState.IsValid)
            {
                db.Entry(shipmentinfo).State = EntityState.Modified;
                db.SaveChanges();
            }
            return Json(JsonResponseFactory.SuccessResponse(shipmentinfo), JsonRequestBehavior.DenyGet);
        }

        //
        // GET: /Shipment/Delete/5
 
        public ActionResult Delete(int id)
        {
            shipmentinfo shipmentinfo = db.shipmentinfo.Find(id);
            return View(shipmentinfo);
        }

        //
        // POST: /Shipment/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            shipmentinfo shipmentinfo = db.shipmentinfo.SingleOrDefault(x=>x.ShipmentId == id);
            db.shipmentinfo.Remove(shipmentinfo);
            db.SaveChanges();
            return Json(JsonResponseFactory.SuccessResponse(shipmentinfo), JsonRequestBehavior.DenyGet);
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}